-module(sub_dispatcher).
-include("protocol.hrl").
-include("subscriber.hrl").
-export([do/3]).

do(forward,_,#sub_packet{dir=unknown}) ->
	ok;
	
do(forward,{wlan,mac,Mac},Packet) ->
	Dest = case sub_dict:do(get,{mac,Mac}) of
		unknown ->
			subscriber_mac:do(create,#subscriber{
								type=wlan,
								mac=Mac,
								ran_info = #sub_wlan{
										ap = (Packet#sub_packet.ran_info)#wlan_spec.ap_ip,
										ac = (Packet#sub_packet.ran_info)#wlan_spec.ac_ip
									}
								}
							);
		Pid ->
			Pid
		end,
	do(forward,Dest,Packet);
	
do(forward,Pid,Packet) when is_pid(Pid) ->
	subscriber_mac:do(forward,Pid,Packet).
	
	

